<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>判断js数据类型</title>
</head>
<body>
<h3>js数据类型：</h3>
<p>值类型（string, number, boolean, undefined, symbool, null）</p>
<p>引用类型（object, array, function）</p>

<p>通用判断可使用Object.prototype.toString.call(value) </p>
<p>可能会影响效率，判断值类型的时候，因为Object.prototype作为原型链的顶层原型</p>
<script>

function getDataType(value) {
  var ret = Object.prototype.toString.call(value).split(' ');
  return ret[1].slice(0, -1);   //String] 过滤]
}

Object.prototype.getDataType = getDataType;

var data = {
  name: 'wei',
  age: 20,
  hasChildren: true,
  interest: ['足球','文学','电脑手机产品','游戏'],
  doSthFn: function(){},
  other1: NaN,
  other2: undefined,
  other3: null
}

for (var key in data) {
  //console.log(getDataType(data[key]))
  console.log( Object.prototype.getDataType(data[key]) )
}

//资料引入
//https://blog.csdn.net/qq_38719039/article/details/81979345

//https://www.cnblogs.com/aniu-caili/p/9439568.html



      //注册接口
      let userpoor = [
        {username: 'xiaod', password: '123456'},
        {username: 'tim', password: '123456'}
      ]
      api.get('/api/register', (req,res) => {
        const {username, password} = req.query
        const userlength = userpoor.filter(v => v.username === username).length

        if (userlength > 0) {
          res.json({
            success: false,
            message: '用户名已存在'
          })
        } else {
          res.json({
            success: true,
            message: '注册成功'
          })
        }

      })


</script>
</body>
</html>